﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace InSilicio.Render.Renderers
{
    /// <summary>
    /// A simple raytracer that merely casts rays, but does have shadows.
    /// Does not to photon mapping or anything special.
    /// </summary>
    public class BasicRaytracer : BaseRenderer
    {
        /// <summary>
        /// Constructs a basic raytracer with shadows, reflection, and refraction.
        /// </summary>
        /// <param name="imgWidth">The width of the image to be rendered.</param>
        /// <param name="imgHeight">The height of the image to be rendered.</param>
        public BasicRaytracer(int imgWidth, int imgHeight)
            : base(imgWidth, imgHeight)
        {
        }

        /// <summary>
        /// Renders the scene to an image.
        /// </summary>
        /// <returns></returns>
        public override Bitmap Render()
        {
            RaytraceScene();
            ApplyPostProcesses();
            return image;
        }

        /// <summary>
        /// Raytraces the scene, placing the color information into a bitmap.
        /// </summary>
        protected void RaytraceScene()
        {
#warning Should add sampler support here in the future.
            for (int x = 0; x < imgWidth; x++)
            {
                for (int y = 0; y < imgHeight; y++)
                {
                    image.SetPixel(x, y, ComputePixelColor(x, y));
                }
            }
        }

        /// <summary>
        /// Computes the color of the pixel located at (x, y) in the image.
        /// </summary>
        /// <param name="x">The x-location of the pixel.</param>
        /// <param name="y">The y-location of the pixel.</param>
        /// <returns>The computed color of the pixel, or black if outside the range of the image.</returns>
        private Color ComputePixelColor(int x, int y)
        {
            // Ensure pixel is a valid location in the image.
            if (x < 0 || x >= imgWidth || y < 0 || y >= imgHeight)
                return Color.Black;
            
            return Color.Black;
        }

        protected void ApplyPostProcesses()
        {

        }
    }
}
